# 公共配置基类
class KylinBaseConfig:
    """Kylin模块公共配置基类"""

    # 腾讯云API配置
    TENCENT_CLOUD = {
        "secret_id": "AKIDkKiuvkNsDNODpGUWMDXlsZ9ZmqiaIn8G",  # 请填入实际的SecretId
        "secret_key": "0mOo23sVwBDE4h7MPGtLcfV8aprgQyKS",  # 请填入实际的SecretKey
        "ocr_service_region": "ap-guangzhou",
        "ocr_service_version": "2018-11-19",
    }
    # tushare接口配置
    TUSHARE_TOKEN = "01403a310ad1878975ec569492b41c52e3b54106d0e5ad9097c8f4f4"

    SFTP_SERVERS = {
        "tencentB": {
            "host": "81.68.200.228",
            "port": 22,
            "user": "root",
            "password": "~z`B/%dGeXP^58W",
            "remote_path": "/root",
        },
        "tencentD": {
            "host": "1.15.174.86",
            "port": 22,
            "user": "root",
            "password": "fby86hu~",
            "remote_path": "/root",
        }
    }


# 开发环境配置
class KylinDev(KylinBaseConfig):
    """开发环境Kylin配置"""

    KYLIN_FILE_PATH = "d:\\tmp\\"


# Mac环境配置
class KylinMac(KylinBaseConfig):
    """Mac环境Kylin配置"""

    KYLIN_FILE_PATH = "/Users/lipan/tmp"


# 生产环境配置
class KylinPrd(KylinBaseConfig):
    """生产环境Kylin配置"""

    KYLIN_FILE_PATH = "/tmp"


# 配置管理类
class KylinConfigManager:
    """Kylin配置管理类，负责配置的获取与合并"""

    # 根据环境获取对应的配置类
    @staticmethod
    def get_config_class(environment=None):
        """
        根据环境获取配置类
        :param environment: 环境标识(dev/mac/prd)
        :return: 对应的配置类
        """
        # 简单的环境判断，避免循环导入
        if environment == "dev":
            return KylinDev
        elif environment == "mac":
            return KylinMac
        else:
            # 默认返回生产环境配置
            return KylinPrd

    # 获取完整配置
    @staticmethod
    def get_config(environment=None):
        """
        获取完整配置，包含公共配置和环境特定配置
        :param environment: 环境标识
        :return: 合并后的配置字典
        """
        config_class = KylinConfigManager.get_config_class(environment)

        # 创建配置字典，包含所有类属性（排除方法和私有属性）
        config = {}
        for attr_name in dir(config_class):
            # 排除方法和私有属性
            if not attr_name.startswith("_") and not callable(
                getattr(config_class, attr_name)
            ):
                config[attr_name] = getattr(config_class, attr_name)

        return config

    # 获取特定配置项
    @staticmethod
    def get_config_item(item_name, environment=None):
        """
        获取特定的配置项
        :param item_name: 配置项名称
        :param environment: 环境标识
        :return: 配置项值
        """
        config_class = KylinConfigManager.get_config_class(environment)

        # 检查配置项是否存在
        if not hasattr(config_class, item_name):
            raise AttributeError(f"配置项 '{item_name}' 不存在")

        return getattr(config_class, item_name)


# 默认配置实例
kylin_config = KylinConfigManager.get_config()
